﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;

namespace SoftSource.Reactive
{
    public class ObservableProperty<T> : IObservableProperty<T>
    {
        Subject<T> subject;

        public ObservableProperty()
        {
            this.subject = new Subject<T>();
        }

        #region IObservableProperty<T> Members

        private T value;
        public T Value
        {
            get { return value; }
            set
            {
                this.value = value;
                this.RaisePropertyChanged("Value");
                this.subject.OnNext(this.Value);
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region IObservable<T> Members

        public IDisposable Subscribe(IObserver<T> observer)
        {
            return subject.Subscribe(observer);
        }

        #endregion
    }
}
